package cc.yiueil.synchronous;

/**
 * ReentrantLock 对于同一个线程, 已经获取到的锁可以重复获得, 叫可重入锁, 有个机制, 有个标志, 重入几次就会增加几, 释放后减少1, 直到减少为0后释放锁
 *
 * @author 弋孓 YIueil@163.com
 * @version 1.0
 * @date 2024/9/24 16:10
 */
public class ReentrantLock {
    private int count = 0;

    public synchronized void add(int n) {
        addDetail(-n);
    }

    public synchronized void addDetail(int n) {
        count += n;
    }

    public static void main(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock();
        reentrantLock.add(-1);
        System.out.println(reentrantLock.count);
    }
}